package cn.steam.foo.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zhang jintao on 2022/05/22
 **/
@WebFilter(filterName = "requestLogFilter", urlPatterns = "/*")
@Order(0)
@Component
@Slf4j
public class RequestLogFilter extends OncePerRequestFilter {


    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        log.info("前---执行,:{}",request);
        filterChain.doFilter(request, response);
        log.info("后---执行:{}",response);
    }
}
